/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    ap-northeast-2-pop = 'arms.aliyuncs.com',
    cn-beijing-finance-1 = 'arms.aliyuncs.com',
    cn-beijing-finance-pop = 'arms.aliyuncs.com',
    cn-beijing-gov-1 = 'arms.aliyuncs.com',
    cn-beijing-nu16-b01 = 'arms.aliyuncs.com',
    cn-edge-1 = 'arms.aliyuncs.com',
    cn-fujian = 'arms.aliyuncs.com',
    cn-haidian-cm12-c01 = 'arms.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'arms.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'arms.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'arms.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'arms.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'arms.aliyuncs.com',
    cn-hangzhou-test-306 = 'arms.aliyuncs.com',
    cn-hongkong-finance-pop = 'arms.aliyuncs.com',
    cn-huhehaote-nebula-1 = 'arms.aliyuncs.com',
    cn-qingdao-nebula = 'arms.aliyuncs.com',
    cn-shanghai-et15-b01 = 'arms.aliyuncs.com',
    cn-shanghai-et2-b01 = 'arms.aliyuncs.com',
    cn-shanghai-inner = 'arms.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'arms.aliyuncs.com',
    cn-shenzhen-inner = 'arms.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'arms.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'arms.aliyuncs.com',
    cn-wuhan = 'arms.aliyuncs.com',
    cn-yushanfang = 'arms.aliyuncs.com',
    cn-zhangbei = 'arms.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'arms.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'arms.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'arms.aliyuncs.com',
    eu-west-1-oxs = 'arms.aliyuncs.com',
    me-east-1 = 'arms.aliyuncs.com',
    rus-west-1-pop = 'arms.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('arms', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ARMSQueryDataSetRequest {
  datasetId?: long(name='DatasetId'),
  dateStr?: string(name='DateStr'),
  dimensions?: [ 
    {
      key?: string(name='Key'),
      type?: string(name='Type'),
      value?: string(name='Value'),
    }
  ](name='Dimensions'),
  hungryMode?: boolean(name='HungryMode'),
  intervalInSec?: int32(name='IntervalInSec'),
  isDrillDown?: boolean(name='IsDrillDown'),
  limit?: int32(name='Limit'),
  maxTime?: long(name='MaxTime'),
  measures?: [ string ](name='Measures'),
  minTime?: long(name='MinTime'),
  optionalDims?: [ 
    {
      key?: string(name='Key'),
      type?: string(name='Type'),
      value?: string(name='Value'),
    }
  ](name='OptionalDims'),
  orderByKey?: string(name='OrderByKey'),
  reduceTail?: boolean(name='ReduceTail'),
  requiredDims?: [ 
    {
      key?: string(name='Key'),
      type?: string(name='Type'),
      value?: string(name='Value'),
    }
  ](name='RequiredDims'),
  securityToken?: string(name='SecurityToken'),
}

model ARMSQueryDataSetResponseBody = {
  data?: string(name='Data'),
}

model ARMSQueryDataSetResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ARMSQueryDataSetResponseBody(name='body'),
}

async function aRMSQueryDataSetWithOptions(request: ARMSQueryDataSetRequest, runtime: Util.RuntimeOptions): ARMSQueryDataSetResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.datasetId)) {
    query['DatasetId'] = request.datasetId;
  }
  if (!Util.isUnset(request.dateStr)) {
    query['DateStr'] = request.dateStr;
  }
  if (!Util.isUnset(request.dimensions)) {
    query['Dimensions'] = request.dimensions;
  }
  if (!Util.isUnset(request.hungryMode)) {
    query['HungryMode'] = request.hungryMode;
  }
  if (!Util.isUnset(request.intervalInSec)) {
    query['IntervalInSec'] = request.intervalInSec;
  }
  if (!Util.isUnset(request.isDrillDown)) {
    query['IsDrillDown'] = request.isDrillDown;
  }
  if (!Util.isUnset(request.limit)) {
    query['Limit'] = request.limit;
  }
  if (!Util.isUnset(request.maxTime)) {
    query['MaxTime'] = request.maxTime;
  }
  if (!Util.isUnset(request.measures)) {
    query['Measures'] = request.measures;
  }
  if (!Util.isUnset(request.minTime)) {
    query['MinTime'] = request.minTime;
  }
  if (!Util.isUnset(request.optionalDims)) {
    query['OptionalDims'] = request.optionalDims;
  }
  if (!Util.isUnset(request.orderByKey)) {
    query['OrderByKey'] = request.orderByKey;
  }
  if (!Util.isUnset(request.reduceTail)) {
    query['ReduceTail'] = request.reduceTail;
  }
  if (!Util.isUnset(request.requiredDims)) {
    query['RequiredDims'] = request.requiredDims;
  }
  if (!Util.isUnset(request.securityToken)) {
    query['SecurityToken'] = request.securityToken;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ARMSQueryDataSet',
    version = '2018-06-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function aRMSQueryDataSet(request: ARMSQueryDataSetRequest): ARMSQueryDataSetResponse {
  var runtime = new Util.RuntimeOptions{};
  return aRMSQueryDataSetWithOptions(request, runtime);
}

